Skip to content

Implement VotingStreakMultiplier #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open

Implement VotingStreakMultiplier #129

wants to merge 24 commits into from

Conversation

secbajor
Copy link
Collaborator

@secbajor secbajor commented Apr 24, 2025

When a vote is cast (via the YieldDistributor), the VotingStreakMultiplier updates it's state variables tracking user's multiplier value and validity.

When this contract is deployed, the front end can call getMultiplyingFactor for the user's current multiplier.

@secbajor secbajor changed the title Sb 127 2 Implement VotingStreakMultiplier Apr 24, 2025
Copy link
Contributor

@bagelface bagelface left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs slight redesign

Copy link
Collaborator

@RonTuretzky RonTuretzky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pattern is implemented as expected! looking very elegant!

@secbajor
Copy link
Collaborator Author

secbajor commented May 8, 2025

@bagelface @RonTuretzky with my latest commit here, the build is compiling without errors/warnings and the tests all pass. Can you advise on next steps?

Copy link
Collaborator

@RonTuretzky RonTuretzky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM so far , please add a VotingStreakMultiplier.t.sol file with unit tests

@secbajor
Copy link
Collaborator Author

@RonTuretzky @bagelface
I resolved ron's feedback. Functionality is in place for voting streak and i believe i added full test coverage.

Can you advise now on next steps?

function mint(address receiver) external payable virtual;
}

contract VotingStreakMultiplierTest is Test {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a Voting multiplier testing section here , would probably be better to refactor this to extend that area

not gonna block this PR on that though tbh, thoughts @bagelface ?

Lets keep in mind this will all be refactored for breadkit anyways

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i moved them to the yd 5376053

Comment on lines 197 to 279
function test_multiplier_increment_after_3_subsequent_cycles() public {
VotingStreakMultiplier multiplier = setUpVotingStreakMultiplier();
address testAccount = setUpTestAccount();
uint256 cycleIterator = 0;
setUpForCycle(yieldDistributor, cycleIterator);

// Initial multiplier should be 0
assertEq(multiplier.getMultiplyingFactor(testAccount), 0);

castVote(testAccount);

// Verify multiplier was updated to multiplierIncrement
assertEq(multiplier.getMultiplyingFactor(testAccount), multiplier.multiplierIncrement());
assertEq(
multiplier.validUntil(testAccount),
yieldDistributor.lastClaimedBlockNumber() + 2 * yieldDistributor.cycleLength()
);

// Roll to the next cycle
cycleIterator++;
setUpForCycle(yieldDistributor, cycleIterator);

castVote(testAccount);

// Verify multiplier was updated to 2 * multiplierIncrement
assertEq(multiplier.getMultiplyingFactor(testAccount), 2 * multiplier.multiplierIncrement());

// Roll to the next cycle
cycleIterator++;
setUpForCycle(yieldDistributor, cycleIterator);

castVote(testAccount);

// Verify multiplier was updated to 3 * multiplierIncrement
assertEq(multiplier.getMultiplyingFactor(testAccount), 3 * multiplier.multiplierIncrement());
}

// when the account has voted in 4 subsequent cycles, the account's multiplier is equal to maxMultiplier
function test_multiplier_increment_after_4_subsequent_cycles() public {
VotingStreakMultiplier multiplier = setUpVotingStreakMultiplier();
address testAccount = setUpTestAccount();
uint256 cycleIterator = 0;
setUpForCycle(yieldDistributor, cycleIterator);

// Initial multiplier should be 0
assertEq(multiplier.getMultiplyingFactor(testAccount), 0);

castVote(testAccount);

// Verify multiplier was updated to multiplierIncrement
assertEq(multiplier.getMultiplyingFactor(testAccount), multiplier.multiplierIncrement());
assertEq(
multiplier.validUntil(testAccount),
yieldDistributor.lastClaimedBlockNumber() + 2 * yieldDistributor.cycleLength()
);

// Roll to the next cycle
cycleIterator++;
setUpForCycle(yieldDistributor, cycleIterator);

castVote(testAccount);

// Verify multiplier was updated to 2 * multiplierIncrement
assertEq(multiplier.getMultiplyingFactor(testAccount), 2 * multiplier.multiplierIncrement());

// Roll to the next cycle
cycleIterator++;
setUpForCycle(yieldDistributor, cycleIterator);

castVote(testAccount);

// Verify multiplier was updated to 3 * multiplierIncrement
assertEq(multiplier.getMultiplyingFactor(testAccount), 3 * multiplier.multiplierIncrement());

// Roll to the next cycle
cycleIterator++;
setUpForCycle(yieldDistributor, cycleIterator);

castVote(testAccount);

// Verify multiplier does not exceed maxMultiplier * multiplierIncrement
assertEq(multiplier.getMultiplyingFactor(testAccount), MAX_MULTIPLIER * MULTIPLIER_INCREMENT);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should be removed in favor of a fuzz test

You can reference the two tests here for how you can turn a vanilla test into a fuzz test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh thats neat! thanks for the tip.

replaced those tests with a fuzz test fe64fc6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants